/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.loli.hernandez.presentacion;

import java.sql.SQLException;
import java.util.ArrayList;
import com.loli.hernandez.modelo.DataManager;

import com.loli.hernandez.modelo.beans.Database;
import com.loli.hernandez.modelo.beans.DatabaseTable;
import com.loli.hernandez.modelo.StoredProcedureGenerator;

/**
 *
 * @author nestor
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String server, user, password, port;
        server = "localhost";
        user = "root";
        password = "";
        port = "3306";
    
       
        DataManager dataManager = new DataManager(server, port, user, password);

        //System.out.println("/*" + dataManager.getUrlConnection() + "*/");

        try {
//            ArrayList<Database> dbList = dataManager.showAllDatabases();
//            for(Database db : dbList){
//                System.out.println("" + db.getDatabaseName());
//            }
            Database db = new Database("northwind");
          dataManager.setDatabase(db);
            ArrayList<DatabaseTable> tableList = dataManager.getTablesFromDatabase();
            for (DatabaseTable table : tableList) {
                if (table.getTableName().toLowerCase().equals("customers")) {
                    StoredProcedureGenerator procGen = new StoredProcedureGenerator(dataManager);
                    System.out.println("" + procGen.getInsert_StoredProcedure(table));
                    System.out.println("" + procGen.getUpdate_StoredProcedure(table));
                    System.out.println("" + procGen.getSelectAll_StoredProcedure(table));
                    System.out.println("" + procGen.getDelete_StoredProcedure(table));
                    System.out.println("" + procGen.getGetDetailsById_StoredProcedure(table));
                }

            }
            //DatabaseTable table1 = tableList.get(0);
//            ArrayList<TableColumn> tableCols = dataManager.getColumnsFromTable(table1);
//            System.out.println(table1.getTableName());
//            for (TableColumn column : tableCols) {
//
//                System.out.println(column.getField() + "--"
//                        + column.getType() + "--"
//                        + column.getDefaultValue() + "--"
//                        + column.getExtra());
//            }


        } catch (SQLException e) {
            System.out.println("" + e.getMessage());
        }
        

    }
}
